IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spTlettertemplate_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spTlettertemplate_RetrieveAll'
		DROP  Procedure  spTlettertemplate_RetrieveAll
	END

GO

PRINT 'Creating Procedure spTlettertemplate_RetrieveAll'
GO

CREATE Procedure spTlettertemplate_RetrieveAll
	(
		@lettertemplateid int = null, 
		@lettertemplatename varchar(50) = null, 
		@lettertemplatetype varchar(50) = null, 
		@lettertemplatedescription varchar(8000) = null, 
		@active numeric = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 9/2/2007	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	Tlettertemplate
	
	WHERE	(@lettertemplateid IS NULL OR Tlettertemplate.lettertemplateid = @lettertemplateid)
	  AND	(@lettertemplatename IS NULL OR Tlettertemplate.lettertemplatename LIKE @lettertemplatename + '%')
	  AND	(@lettertemplatetype IS NULL OR Tlettertemplate.lettertemplatetype LIKE @lettertemplatetype + '%')
	  AND	(@lettertemplatedescription IS NULL OR Tlettertemplate.lettertemplatedescription LIKE @lettertemplatedescription + '%')
	  AND	(@active IS NULL OR Tlettertemplate.active = @active)

	-- Return to calling method
	RETURN
GO
